<template>
	<view class="fui-wrap">
		<view v-if="err" style="padding-top: 220rpx;">
			<fui-result type="fail" title="操作失败" :descr="err">
				<fui-button @click="$reLaunch('index/index')" width="400rpx" height="84rpx" text="返回主页" type="success" bold :margin="['48rpx','0','24rpx']"></fui-button>
			</fui-result>
		</view>
	</view>	
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	export default {
		data() {
			return {
				err:''
			}
		},
		onLoad(query) {
			// #ifdef MP-ALIPAY
			let q = my.getLaunchOptionsSync();
			let r = q.query.qrCode;
			// #endif
			// #ifdef MP-WEIXIN
			let r = decodeURIComponent(query.q);
			// #endif
			let methods=this.queryURLmethods(r);
			let {serialno,uniqid,temp_id,parking_id,plate_number,records_id} = this.queryURLparams(r);
			//商户主页
			if(methods=='merchant'){
				this.$reLaunch('merchant/index');
			}
			//管理主页
			if(methods=='admin'){
				this.$reLaunch('parking/index');
			}
			//用户主页
			if(methods=='miniapp'){
				this.$reLaunch('index/index');
			}
			//场内缴费
			if(methods=='stock'){
				this.$get('index/parking',{uniqid:uniqid}).then(res=>{
					this.$reLaunch('index/plate?type=parking&parking_id='+res.id);
				});
			}
			//支付月租
			if(methods=='monthly'){
				this.$get('index/parking',{uniqid:uniqid}).then(res=>{
					this.$reLaunch('index/plate?type=monthly_apply&parking_id='+res.id);
				});
			}
			//支付储值卡
			if(methods=='stored'){
				this.$get('index/parking',{uniqid:uniqid}).then(res=>{
					this.$reLaunch('index/plate?type=stored_apply&parking_id='+res.id);
				});
			}
			//出场
			if(methods=='exit'){
				this.$reLaunch('index/parking?serialno='+serialno);
			}
			//停车付款界面
			if(methods=='records'){
				this.$reLaunch('index/parking?records_id='+records_id);
			}
		},
		methods: {
			...methods,
			queryURLmethods:function(url){
				let host=baseUrl.slice(8)
				let len=host.length+7;
				let startIndex=url.indexOf(host+'qrcode')+len;
				let endIndex=url.indexOf('?');
				return url.slice(startIndex,endIndex);
			},
			queryURLparams:function(url) {
			    let obj = {}
			    if (url.indexOf('?') < 0) return obj
			    let arr = url.split('?')
			    url = arr[1]
			    let array = url.split('&')
			    for (let i = 0; i < array.length; i++) {
			        let arr2 = array[i]
			        let arr3 = arr2.split('=')
			        obj[arr3[0]] = arr3[1]
			    }
			    return obj	
			}
		}
	}
</script>

<style>
	
</style>